#region Summary

// 
// Owner : JackieHan 
// 
// Solution : ResearchTest 
// 
// Project : Jackie.Json.Test
// 
// File : TestJsonSerialize.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : 测试json的序列化与反序列化
// 
// History : 
//			2011-05-13 11:26:57	    Create 
// 

#endregion

#region Using

using System;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NUnit.Framework;

#endregion

namespace Jackie.Json.Test
{
    /// <summary> 
    /// 测试json的序列化与反序列化
    /// </summary>
    [TestFixture]
    public class TestJsonSerialize
    {
        private PromotionInfo promotionInfo;

        [SetUp]
        public void SetUp()
        {
            promotionInfo = new PromotionInfo
                                {
                                    Promotions = new Dictionary<string, IDictionary<string, List<string>>>
                                                     {
                                                         {
                                                             "pmt", new Dictionary<string, List<string>>
                                                                        {
                                                                            {
                                                                                "goods", new List<string> {"商品促销1", "商品促销2"}
                                                                                },
                                                                            {
                                                                                "order",
                                                                                new List<string>() {"活动促销名!", "活动促销名2"}
                                                                                }
                                                                        }
                                                             },
                                                         {
                                                             "coupon", new Dictionary<string, List<string>>
                                                                           {
                                                                               {
                                                                                   "goods",
                                                                                   new List<string> {"商品促销1", "商品促销2"}
                                                                                   },
                                                                               {
                                                                                   "order",
                                                                                   new List<string>()
                                                                                       {"活动促销名!", "活动促销名2"}
                                                                                   }
                                                                           }
                                                             }
                                                     },
                                    SpecialPromotion = new Dictionary<string, List<string>>
                                                           {
                                                               {"limitpower", new List<string> {"限时抢购"}},
                                                               {"golobal_oneplusone", new List<string> {"全场1+1"}},
                                                               {"oneplusone", new List<string> {"区域1+1"}}
                                                           }
                                };
        }

        [Test]
        public void TestSerializer()
        {
            string result = JsonConvert.SerializeObject(promotionInfo);
            Console.WriteLine(result);
        }

        [Test]
        public void TestDeserializer()
        {
            var jsonStr =
                "{'pmt':{'goods':['\u5546\u54c1\u4fc3\u9500\u540d1','\u5546\u54c1\u4fc3\u9500\u540d2'],'order':['\u6d3b\u52a8\u4fc3\u9500\u540d1','\u6d3b\u52a8\u4fc3\u9500\u540d2']},'limitpower':['\u9650\u65f6\u62a2\u8d2d'],'coupon':{'goods':['\u5546\u54c1\u4f18\u60e0\u52381','\u5546\u54c1\u4f18\u60e0\u52382'],'order':['\u8ba2\u5355\u4f18\u60e0\u52381','\u8ba2\u5355\u4f18\u60e0\u52382']},'golobal_oneplusone':['\u5168\u573a1+1'],'oneplusone':['\u533a\u57df1+1']}";
            var object1 = JsonConvert.DeserializeObject(jsonStr);
            var jsonArray = new JArray(object1);
            Console.WriteLine(jsonArray[0]);
        }

        [TearDown]
        public void TearDown()
        {
        }

    }
}